package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2018/12/17 14:23
 * @description
 */
public class Code942 {
    public int[] diStringMatch(String S) {
        int start = 0, end = S.length();
        int[] result = new int[end + 1];
        char[] chars = S.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == 'I') {
                result[i] = start++;
            } else {
                result[i] = end--;
            }
            if (i == chars.length - 1) {
                if (chars[chars.length - 1] == 'I') {
                    result[chars.length] = start++;
                } else {
                    result[chars.length] = end++;
                }
            }
        }
        return result;
    }
}
